<?php
$iMissionID = $_REQUEST['iMissionID'];
$oJobs = JobHandler::getJobs();
$oMissions = $oJobs[$_SESSION['iJobID']]->getMissions(false, true);
$bChange = JobHandler::canDo('mission', 'write');

$oUsers = UserHandler::getUsers();
$oMission = $oMissions[$iMissionID];
$sMissionStatus = MissionHandler::getStatuses();
$sMissiongroups = $oJobs[$_SESSION['iJobID']]->getMissiongroups();
$oJobConfig = $oJobs[$_SESSION['iJobID']]->getConfig();
$iChangers = JobHandler::getUsersWithAccess('mission', 'write');

$oFiles = JobHandler::getFiles($_SESSION['iJobID']);
$iMissionFiles = MissionHandler::getFiles($iMissionID);
?>

<table style="width: 100%;" cellspacing="0">
	<tr>
		<td style="padding: 0px 0px 0px 0px;">
<?php
if ($bChange)
{
	?>
			<script language="JavaScript">
				function mission_show_checkfinishtime()
				{
					oForm = document.form_mission_show;
					if (oForm.bFinishTime.checked)
					{
						oForm.iYear.disabled = false;
						oForm.iMonth.disabled = false;
						oForm.iDay.disabled = false;
						oForm.iHour.disabled = false;
					}
					else
					{
						oForm.iYear.disabled = true;
						oForm.iMonth.disabled = true;
						oForm.iDay.disabled = true;
						oForm.iHour.disabled = true;
					}
				}
			</script>
			<form action="index.php" method="post" name="form_mission_show">
			<input type="hidden" name="sAction" value="mission-change">
			<input type="hidden" name="sView" value="mission-show">
			<input type="hidden" name="iMissionID" value="<?php print $_REQUEST['iMissionID'] ?>">
			<input type="hidden" name="bAssign" value="1">
	<?php
	if (count($iChangers) == 1) {
		?>
			<input type="hidden" name="iUsers[]" value="<?php print $_SESSION['rid'] ?>">
		<?php
	}
}
?>
			<table cellspacing="0" style="width: 100%;">
				<tr>
					<td class="fieldname"><?php print msg('Task') ?>:</td>
					<td class="fieldvalue">
<?php
if ($bChange)
{
	echo '<input type="text" name="sTodo" value="'.str_replace('"', '&quot;', $oMission->sTodo).'" size="60" id="focus_mission_show">';
}
else
{
	echo $oMission->sTodo;
}
?>
					</td>
				</tr>
<?php
if (count($sMissiongroups) > 0) {
	?>
				<tr>
					<td class="fieldname"><?php print msg('Group') ?>:</td>
					<td class="fieldvalue">
	<?php
	if ($bChange)
	{
		echo '<select name="iMissiongroupID">';
		if ($oJobConfig['bAllowNogroupMissions'])
		{
			echo '<option value="0">[ '.msg('None').' ]</option>';
		}
		foreach ($sMissiongroups as $iThisID => $sThisMissiongroup)
		{
			echo '<option value="'.$iThisID.'" '.($iThisID == $oMission->iGroup ? 'selected' : '').'>'.$sThisMissiongroup.'</option>';
		}
		echo '</select>';
	}
	else
	{
		echo $sMissiongroups[$oMission->iGroup];
	}
	?>
					</td>
				</tr>
	<?php
}
?>
				<tr>
					<td class="fieldname"><?php print msg('Status') ?>:</td>
					<td class="fieldvalue">
<?php
if ($bChange)
{
	echo '<select class="missionstatus'.$oMission->iStatus.'" style="padding: 0px 0px 0px 0px;" name="iStatus">';
	for ($i = 0; $i < count($sMissionStatus); $i++)
	{
		echo '<option class="missionstatus'.$i.'" value="'.$i.'" '.($i == $oMission->iStatus ? 'selected' : '').'>'.$sMissionStatus[$i]['caption'].'</option>';
	}
	echo '</select>';
}
else
{
	echo $sMissionStatus[$oMission->iStatus]['caption'];
}
?>
					</td>
				</tr>
				<tr>
					<td class="fieldname"><?php print msg('Urgency') ?>:</td>
					<td class="fieldvalue">
<?php
if ($bChange)
{
	echo '<select name="iUrgency">';
	for ($i = 0; $i < count($oJobs[$_SESSION['iJobID']]->sUrgencies); $i++)
	{
		echo '<option value="'.$i.'" '.($i == $oMission->iUrgency ? 'selected' : '').'>'.$oJobs[$_SESSION['iJobID']]->sUrgencies[$i].'</option>';
	}
	echo '</select>';
}
else
{
	echo $oJobs[$_SESSION['iJobID']]->sUrgencies[$oMission->iUrgency];
}
?>
					</td>
				</tr>
				<tr>
					<td class="fieldname"><?php print msg('Deadline') ?>:</td>
					<td class="fieldvalue">
<?php
if ($bChange)
{
	?>
						<?php print msg('Active') ?>:
						<input type="checkbox" name="bFinishTime" onClick="
							oForm = document.form_mission_show;
							oForm.iYear.disabled = !this.checked;
							oForm.iMonth.disabled = !this.checked;
							oForm.iDay.disabled = !this.checked;
							oForm.iHour.disabled = !this.checked;
						" <?php print ($oMission->iFinishTime ? 'checked' : '') ?>>
						<table cellspacing="0">
							<tr>
								<td class="fieldvalue small center"><?php print msg('Year') ?></td>
								<td class="fieldvalue small center"><?php print msg('Month') ?></td>
								<td class="fieldvalue small center"><?php print msg('Day') ?></td>
							</tr>
							<tr>
								<td class="fieldvalue small center"><input type="text" size="4" maxlength="4" name="iYear" value="<?php print $oMission->iFinishTime ? date('Y', $oMission->iFinishTime) : date('Y') ?>" <?php print $oMission->iFinishTime ? '' : 'disabled' ?>></td>
								<td class="fieldvalue small center"><input type="text" size="2" maxlength="2" name="iMonth" value="<?php print $oMission->iFinishTime ? date('m', $oMission->iFinishTime) : date('m') ?>" <?php print $oMission->iFinishTime ? '' : 'disabled' ?>></td>
								<td class="fieldvalue small center"><input type="text" size="2" maxlength="2" name="iDay" value="<?php print $oMission->iFinishTime ? date('d', $oMission->iFinishTime) : date('d') ?>" <?php print $oMission->iFinishTime ? '' : 'disabled' ?>></td>
							</tr>
							<tr>
								<td class="fieldvalue small" colspan="3"><?php print msg('Time') ?>: <input type="text" size="2" maxlength="2" name="iHour" value="<?php print $oMission->iFinishTime ? date('H', $oMission->iFinishTime) : '17' ?>" <?php print $oMission->iFinishTime ? '' : 'disabled' ?>>:00</td>
							</tr>
						</table>
	<?php
}
else
{
	if ($oMission->iFinishTime)
	{
		echo coolDate($oMission->iFinishTime);
	}
	else
	{
		echo '[ '.msg('Undefined').' ]';
	}
}
?>
					</td>
				</tr>
<?php
if (count($iChangers) > 1) {
	?>
				<tr>
					<td class="fieldname"><?php print msg('Assignment') ?>:</td>
					<td class="fieldvalue">
	<?php
	if ($bChange)
	{
		foreach ($iChangers as $iThisChanger)
		{
			echo '<input type="checkbox" name="iUsers[]" value="'.$iThisChanger.'" onClick="mission_show_checkusers();" '.(in_array($iThisChanger, $oMission->iUsers) ? 'checked' : '').'>'.$oUsers[$iThisChanger]->sUser.'<br>';
		}
	}
	else
	{
		$bFirst = true;
		foreach ($oMission->iUsers as $iThisUser)
		{
			if (!$bFirst)
			{
				echo ', ';
			}
			echo $oUsers[$iThisUser]->sUser;
			$bFirst = false;
		}
	}
	?>
					</td>
				</tr>
	<?php
}

if (count($oFiles) > 0) {
	?>
				<tr>
					<td class="fieldname">Files:</td>
					<td class="fieldvalue">
	<?php
	foreach ($oFiles as $oThisFile) {
		print '<input type="checkbox" name="iFiles[]" value="'.$oThisFile->iID.'" '.(in_array($oThisFile->iID, $iMissionFiles) ? 'checked' : '').'> '.($oThisFile->sDescription ? $oThisFile->sDescription : $oThisFile->sFilename).'<br>';
	}
	?>
					</td>
				</tr>
	<?php
}

if (count($oJobs) > 1) {
	?>
				<tr>
					<td class="fieldname"><?php print msg('Project') ?>:</td>
					<td class="fieldvalue">
	<?php
	if ($bChange)
	{
		jobSelector();
		echo ' <input type="button" value="'.msg('Move').'" onClick="location.href = \'index.php?sAction=mission-changejob&iMissionID='.$oMission->iID.'&iJobID=\' + document.form_mission_show.iJob.value;"></td>';
	}
	else
	{
		echo $oJobs[$_SESSION['iJobID']]->sName;
	}
}
?>
				</tr>
				<tr>
					<td class="fieldname"><?php print msg('Requested') ?>:</td>
					<td class="fieldvalue"><?php print coolDate($oMission->iRequestTime) ?></td>
				</tr>
				<tr>
					<td class="fieldname"><?php print msg('Requester') ?>:</td>
					<td class="fieldvalue"><a href="index.php?sView=user-view&iUser=<?php print $oMission->iRequester ?>"><?php print $oUsers[$oMission->iRequester]->sUser ?></a></td>
				</tr>
				<tr>
					<td class="fieldname"><?php print msg('Task ID') ?>:</td>
					<td class="fieldvalue"><?php print $oMission->sRequestID ?></td>
				</tr>
				<tr>
					<td class="fieldname"><?php print msg('Assignment time') ?>:</td>
					<td class="fieldvalue"><?php print coolDate($oMission->iAssignTime) ?></td>
				</tr>
<?php
if ($bChange)
{
	?>
				<tr>
					<td class="boxbody center" colspan="2">
						<input type="submit" value="<?php print msg('OK') ?>">
						<input type="button" value="<?php print msg('Cancel') ?>" onClick="layerHide('layer_mission_show');">
					</td>
				</tr>
	<?php
}
?>
			</table>
<?php
if ($bChange)
{
	?>
			<script language="JavaScript">
				mission_show_checkfinishtime();
			</script>
			</form>
	<?php
}
?>
		</td>
	</tr>
</table>

